import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import SystemRouter from './SystemRouter'
import GoodsRouter from './GoodsRouter'
import GenRouter from './GenRouter'
import OrderRouter from './OrderRouter'
import MarketingRouter from './MarketingRouter'
import BasicRouter from './BasicRouter'
import AccountingRouter from './AccountingRouter'
import WmsRouter from './WmsRouter'
/**
 * 公共路由
 * Note: 路由配置项
 * hidden: true                  // 当 hidden 为 true 时, 该路由不会在侧边栏显示，默认为 false。
 * alwaysShow: true              // 当 alwaysShow 为 true 时，该路由会在侧边栏一直显示。
 *                               // 当 alwaysShow 为 false 时，
 *                               //   如果该路由只有一个子路由时，则将子路由当作根路由显示在侧边栏。
 *                               //   如果该路由有多个子路由时，则该路由将称为嵌套模式。
 * redirect: noRedirect          // 当 redirect 为 noRedirect 时，该路由在面包屑导航栏中不可被点击。
 * name:'router-name'            // 路由名称，必须填写，不能重复，不然 <keep-alive> 会出现bug。
 * meta : {
 *  title: 'title'               // 路由在侧边栏和面包屑导航栏中显示的名称
 *  icon: 'svg-name'/'el-icon-x' // 路由图标
 *  noCache: true                // 如果设置为 true，该路由在 <keep-alive> 中不被缓存，默认为 false。
 *  breadcrumb: false            // 如果设置为 false，该路由不会在面包屑导航栏中显示，默认为 true。
 * }
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/Login'),
    hidden: true
  },
	{
		path: '/401',
		component: (resolve) => require(['@/views/error/401'], resolve),
		hidden: true
	},
	{
		path: '/404',
		component: () => import('@/views/error/404'),
		hidden: true
	},
	{
		path: '/register',
		component: () => import('@/views/register/register'),
		hidden: true
	},
	{
		path: '/company',
		component: () => import('@/views/register/company/company'),
		hidden: true
	},
	{
		path: '/companyRegister',
		component: () => import('@/views/register/company/companyRegister'),
		hidden: true
	},
	{
		path: '/capital',
		component: () => import('@/views/register/capital/capital'),
		hidden: true
	},
	{
		path: '/capitalRegister',
		component: () => import('@/views/register/capital/capitalRegister'),
		hidden: true
	},
	{
		path: '/',
		component: Layout,
		redirect: '/calendar',
		children: [
		  {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: {
          title: '首页',
          icon: 'dashboard',
          noCache: true,
          affix: true
        },
        hidden: false
      },
      {
        path: '/calendar',
        component: () => import('@/views/dashboard/calendar'),
        meta: {
          title: '日历',
          icon: 'dashboard',
          noCache: true,
          affix: true
        },
        hidden: false
      },
      {
        path: '/tbWmsLocation3D',
        component: () => import('@/views/web/tbWmsLocation/TbWmsLocation3D'),
        meta: {
          title: '3D库区',
          icon: '',
          noCache: true,
          affix: true
        },
        hidden: false
      }
		]
	},
	...SystemRouter,
	...GenRouter,
	...GoodsRouter,
	...OrderRouter,
	...MarketingRouter,
	...BasicRouter,
  ...WmsRouter,
	...AccountingRouter
]

const createRouter = () => new Router({
	// mode: 'history', // require service support
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
